package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.AcademyCategoryService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.AcademyCategoryBo;
import com.ddwl.schema.bo.goods.QueryAcademyCategoryBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.AcademyCategoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 商学院分类管理
 *
 * @author wenbin
 */
@Api(tags = "商学院文章分类")
@RequestMapping("AcademyCategory")
@RestController
public class AcademyCategoryController extends BaseController {

    @Resource
    private AcademyCategoryService academyCategoryService;


    @PostMapping("academyCategoryListConsole")
    @ApiOperation("查询商学院分类列表(后台)")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<PageVo<AcademyCategoryVo>> academyCategoryListConsole(@RequestBody PageBo<QueryAcademyCategoryBo> pageBo) {
        return RestVo.ok(academyCategoryService.academyCategoryList(pageBo));
    }

    @PostMapping("academyCategoryList")
    @ApiOperation("查询商学院分类列表")
    @Auth(product = {BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.FENXIAO})
    public RestVo<PageVo<AcademyCategoryVo>> academyCategoryList(@RequestBody PageBo<QueryAcademyCategoryBo> pageBo) {
        pageBo.getParam().setEffect(1);
        return RestVo.ok(academyCategoryService.academyCategoryList(pageBo));
    }

    @GetMapping("/list")
    @ApiOperation("app和小程序查询分类标签")
    @Auth(product = {BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.FENXIAO})
    public RestVo<List<AcademyCategoryVo>> getList() {
        return RestVo.ok(academyCategoryService.getList());
    }

    @PostMapping("/createAcademyCategory")
    @ApiOperation("创建文章类型")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo createAcademyCategory(@Valid @RequestBody AcademyCategoryBo bo) {
        academyCategoryService.createAcademyCategory(bo, getUserId());
        return RestVo.ok();
    }

    @PostMapping("/updateAcademyCategory")
    @ApiOperation("修改文章类型")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo updateAcademyCategory(@Valid @RequestBody AcademyCategoryBo bo) {
        academyCategoryService.updateAcademyCategory(bo, getUserId());
        return RestVo.ok();
    }

    @DeleteMapping("deleteAcademyCategory/{id}")
    @ApiOperation("删除文章类型")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo deleteAcademyCategory(@PathVariable("id") String id) {
        academyCategoryService.deleteAcademyCategory(id, getUserId());
        return RestVo.ok();
    }


}
